import { defineStore } from "pinia";
export const useMainStore = defineStore("main", {
  state: () => {
    return {
      userInfo: {} as any,
      studentInfo: {} as any,
      cobreedingTaskId: "",
      cobreedingTaskName: "",
      refreshTask: false,
    };
  },
  actions: {
    setRefreshTask(refreshTask: boolean) {
      this.refreshTask = refreshTask;
    },
    setCobreedingTaskId(cobreedingTaskId: string) {
      this.cobreedingTaskId = cobreedingTaskId;
    },
    setCobreedingTaskName(cobreedingTaskName: string) {
      this.cobreedingTaskName = cobreedingTaskName;
    },
    setUserInfo(userInfo: object) {
      this.userInfo = userInfo;
    },
    setStudentInfo(studentInfo: object) {
      this.studentInfo = studentInfo;
    },
  },
});

enum PositionEnum {
  CANTEEN = 1,
  PLAYGROUND = 2,
  LIBRARY = 3,
  CLASSROOM = 4,
  GYM = 5,
  DORMITORY = 6,
}
export const useAnimationStore = defineStore("animation", {
  state: () => {
    return {
      list: [] as string[],
    };
  },
  actions: {
    setList(list: any) {
      if (!list) return;
      this.list = list
        .map((item: any) => {
          const value = PositionEnum[item];
          return value;
        })
        .filter(
          (value: string | any[]): value is string =>
            typeof value === "string" && value.length > 0
        );
    },
  },
});

export const useMusicStore = defineStore("music", {
  state: () => {
    return {
      volume: 0.5,
      isPlay: false,
    };
  },
  actions: {
    setIsPlay(isPlay: boolean) {
      this.isPlay = isPlay;
    },
    setVolume(volume: number | string) {
      this.volume = Number(volume);
    },
  },
});
